#include "cpu.h"

#include "common.h"

static void set_value(GtkWidget * widget, gpointer cpu)
{
    GtkRange *range = (GtkRange *) widget;

    gtk_cpu_set_sel(GTK_CPU(cpu), gtk_range_get_value(range));
}

int main( int argc, char *argv[]){
    GtkWidget *window;
    GdkColor  color_ = {0x0, 0x50, 0x50, 0x50};

    GtkWidget *fixed;
    GtkWidget *cpu;
    GtkWidget *vscale;

    gtk_init(&argc, &argv);

    /* window */
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
#if 0
    gtk_window_fullscreen(GTK_WINDOW(window));              /*设置全屏*/
#else
    gtk_widget_set_size_request (window, 750, 550);         /*设置窗口大小*/
    gtk_window_set_resizable(GTK_WINDOW(window), FALSE);    /*设置窗口不能拉伸*/
#endif
    gtk_window_set_title(GTK_WINDOW(window), TITLE);
    //    gtk_container_set_border_width(GTK_CONTAINER(window), 15);  /*设置容器边界大小*/
//    gtk_widget_modify_bg(window, GTK_STATE_NORMAL, &color_); /*设置为背景颜色*/
    //    gtk_window_set_decorated(GTK_WINDOW(window), FALSE);	/*设置不提供装饰*/
    GTK_WINDOW(window)->allow_shrink = TRUE;

    /* demo */

    cpu = gtk_cpu_new();

    fixed = gtk_fixed_new();
    gtk_container_add(GTK_CONTAINER(window), fixed);
    gtk_fixed_put(GTK_FIXED(fixed), cpu, 30, 40);

    vscale = gtk_vscale_new_with_range(0.0, 100.0, 1.0);
    gtk_range_set_inverted(GTK_RANGE(vscale), TRUE);
    gtk_scale_set_value_pos(GTK_SCALE(vscale), GTK_POS_TOP);
    gtk_widget_set_size_request(vscale, 50, 120);
    gtk_fixed_put(GTK_FIXED(fixed), vscale, 130, 20);
    g_signal_connect(G_OBJECT(vscale), "value_changed", G_CALLBACK(set_value), (gpointer) cpu);

    /* signal setting */
    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}
